package ACWing.Greed;
//125. 耍杂技的牛

import java.util.ArrayList;
import java.util.Comparator;
import java.util.List;
import java.util.Scanner;

/**
 * @author :chenjie
 * @date :Created 2023/1/16 14:37
 */
public class TheAcrobaticCow {
    static class Pall{
        int x;
        int y;
        public Pall(int x, int y) {
            this.x = x;
            this.y = y;
        }
    }
    public static void main(String[] args) {
        Scanner sc=new Scanner(System.in);
        int n=sc.nextInt();
        List<Pall> list=new ArrayList<>();
        for (int i = 0; i < n; i++) {
            list.add(new Pall(sc.nextInt(),sc.nextInt()));
        }
        list.sort(new Comparator<Pall>() {
            @Override
            public int compare(Pall o1, Pall o2) {
//                if(o1.y==o2.y){
//                    return o1.x-o2.x;
//                }
                return (o1.x+o1.y)-(o2.x+o2.y);
            }
        });
        long sum=0,max= (long) -1E9;
        for (int i = 0; i <list.size(); i++) {
            max=Math.max(max,sum-list.get(i).y);
            sum+=list.get(i).x;
        }
        System.out.println(max);
    }
}
